package com.siblings.loan.ui.steps.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.lib.base.utils.ImageUtil
import com.siblings.lib_baseadapter.SIBRecyclerViewAdapter
import com.siblings.lib_baseadapter.SIBViewHolderHelper
import com.siblings.loan.R
import org.json.JSONObject

/**
 * Siblings
 * @Author wwdeng
 * @CreateTime: 2024/4/19 12:02
 * @Annotation：绑卡适配器
 */
class SibStepAccountAdapter(recyclerView: RecyclerView?): SIBRecyclerViewAdapter<JSONObject>(recyclerView) {

    override fun getItemViewType(position: Int): Int {
        val model = getItem(position)
        if (model.optBoolean("isEdit",false)){
            return R.layout.item_account_edit
        }
        return R.layout.item_account_index
    }

    override fun setItemChildListener(helper: SIBViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.editLayout) //点击编辑
        helper.setItemChildClickListener(R.id.deleteLayout)//删除
    }

    override fun fillData(helper: SIBViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.textIndex,String.format(mContext.getString(R.string.step_bind_card_index),position+1))

        //是否是编辑
        val isEdit = model.optBoolean("isEdit",true)
        if (!isEdit){
            helper.setText(R.id.textName,model.optString("walletDesc"))
            helper.setText(R.id.textNumber,"+" + model.optString("walletMobile"))

            val imgLogo = helper.getImageView(R.id.imgLogo)
            ImageUtil.instance!!.loadImageUrl(mContext,imgLogo,model.optString("walletLogo"), com.lib.base.R.mipmap.icon_holder)

            //是否显示 删除按钮
            if (model.has("isShowDelete") && !model.optBoolean("isShowDelete")){
                helper.setVisibility(R.id.deleteLayout, View.GONE)
            } else {
                helper.setVisibility(R.id.deleteLayout, View.VISIBLE)
            }
        }
    }
}